package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.modular.business.dto.DeviceAddDto;
import cn.stylefeng.guns.modular.business.dto.DeviceQuery;
import cn.stylefeng.guns.modular.business.dto.DeviceUpdateDto;
import cn.stylefeng.guns.modular.business.service.DeviceBrandService;
import cn.stylefeng.guns.modular.business.service.DeviceService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/device")
@Api(tags = "设备管理接口", description = "设备管理相关接口")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @Autowired
    private DeviceBrandService deviceBrandService;

    @GetMapping("/findPage")
    @ApiOperation("分页查询设备接口")
    public ResponseData page(@Validated DeviceQuery deviceQuery) {
        return new SuccessResponseData(this.deviceService.findPage(deviceQuery));
    }


    @GetMapping("/detail")
    @ApiOperation("查询设备详情接口")
    public ResponseData detail(@RequestParam("id") Integer id) {
        return new SuccessResponseData(this.deviceService.detail(id));
    }

    @GetMapping("/brandList")
    @ApiOperation("不分页查询设备品牌")
    public ResponseData brandList() {
        return new SuccessResponseData(this.deviceBrandService.list());
    }


    @PostMapping("/edit")
    @ApiOperation("编辑设备")
    public ResponseData edit(@RequestBody  @Validated DeviceUpdateDto deviceUpdateDto) {
        this.deviceService.edit(deviceUpdateDto);
        return new SuccessResponseData();
    }

    @PostMapping("/add")
    @ApiOperation("添加设备")
    public ResponseData edit(@RequestBody  @Validated DeviceAddDto deviceAddDto) {
        this.deviceService.add(deviceAddDto);
        return new SuccessResponseData();
    }

    @GetMapping("/statistics")
    @ApiOperation("统计设备")
    public ResponseData statistics() {
        Map<String, Object> map = this.deviceService.statistics();
        return new SuccessResponseData(map);
    }



}
